let list = null
let hot = null
let newTxt = null
let newlist = null
async function get(page, limit, cateid, lsitname) {
  list = await axios({
    url: 'index/index',
  }).then(res => {
    return res.data.data
  })
  hot = await axios({
    url: 'index/recommend',
  }).then(res => {
    return res.data.data
  })
  newTxt = await axios({
    url: 'index/hot',
  }).then(res => {
    return res.data.data
  })

  newlist = await axios({
    url: 'index/list',
    params: {
      page,
      limit,
      cateid,
    },
  }).then(res => {
    return {
      some: res.data.data,
    }
  })

  await new Vue({
    el: '.shw',
    data: {
      allCate: list.allCate,
      banner: list.banner,
      sideBanner: list.sideBanner,
      allTag: list.allTag,
      allLink: list.allLink,
      list: hot.list,
      newTxt: newTxt.list,
      lsitname,
      newlist: newlist.some.list.data,
      // newIndex: newIndex,
      token: localStorage.getItem('token'),
      user: localStorage.getItem('user')
        ? JSON.parse(localStorage.getItem('user'))
        : null,
      loc: loc2,
    },
    filters: {
      www(val) {
        let day = new Date(val).getDate()
        day = day < 10 ? '0' + day : day
        let m = new Date(val).getMonth() + 1
        m = m < 10 ? '0' + m : m
        let y = new Date(val).getFullYear()
        y = y < 10 ? '0' + y : y
        return y + '-' + m + '-' + day
      },
    },
    conputed: {},
    methods: {
      fy(e) {
        if (e.target.localName === 'a' || e.taget.localName === em) {
          this.newlist = newlist.some
          console.log(newlist)
        }
      },
      rem() {
        layer.confirm(
          '确认退出？',
          {
            btn: ['确认', '取消'], //可以无限个按钮
          },
          function (index, layero) {
            //按钮【按钮一】的回调
            localStorage.clear()
            history.go(0)
          },
          function (index) {
            //按钮【按钮二】的回调
          },
        )
      },
    },
  })
  layui.use('laypage', function () {
    var laypage = layui.laypage

    //执行一个laypage实例
    laypage.render({
      elem: 'test1', //注意，这里的 test1 是 ID，不用加 # 号
      count: newlist.some.list.count, //数据总数，从服务端得到
      jump: function (obj, first) {
        //obj包含了当前分页的所有参数，比如：
        // console.log(obj.curr)
        // count = obj.curr
        //得到当前页，以便向服务端请求对应页的数据。
        axios({
          url: 'index/list',
          params: {
            page: obj.curr,
            cateid: loc2,
          },
        }).then(res => {
          console.log(res.data.data.list.data)
          newlist.some = res.data.data.list.data
        })
        //首次不执行
        if (!first) {
          //do something
        }
      },
    })
  })
}
let loc = location.search.substring(1).split('&')
let loc1 = loc[0].split('=')[1]
let loc2 = loc[1].split('=')[1]

get(1, 10, loc2, decodeURIComponent(loc1))
